﻿Imports System
Imports System.Text
Imports System.Drawing
'Imports MyLib.WindowsForms.Properties
Imports System.Windows.Forms

Public Class StylesCouleurs
    Implements IDisposable

#Region "Variables Private"

    Friend _Color_DegradeClair0 As Color
    Friend _Color_DegradeClair1 As Color
    Friend _Color_DegradeFonce0 As Color
    Friend _Color_DegradeFonce1 As Color
    Friend _Color_DegradeFocusClair0 As Color
    Friend _Color_DegradeFocusClair1 As Color
    Friend _Color_DegradeFocusFonce0 As Color
    Friend _Color_DegradeFocusFonce1 As Color
    Friend _Color_Back As Color
    Friend _Color_BackForm As Color
    Friend _Color_Text As Color
    Friend _Color_Text_Focus As Color
    Friend _Color_Text_Desabled As Color
    Friend _Color_Titre As Color
    Friend _Color_Borders As Color

    Private _Pen_DegradeClair0 As Pen
    Private _Pen_DegradeClair1 As Pen
    Private _Pen_DegradeFonce0 As Pen
    Private _Pen_DegradeFonce1 As Pen
    Private _Pen_Borders As Pen

    Private _Brush_DegradeClair0 As Brush
    Private _Brush_DegradeClair1 As Brush
    Private _Brush_DegradeFonce0 As Brush
    Private _Brush_DegradeFonce1 As Brush
    Private _Brush_Text As Brush
    Private _Brush_Text_Focus As Brush
    Private _Brush_Text_Desabled As Brush
    Private _Brush_Titre As Brush

#End Region

#Region "Creation d'une instance"

    ''' <summary>
    ''' Chargemnt des paramètres couleurs de l'appli
    ''' </summary>
    Public Sub New()
        ' Chargement des paramètres de l'appli
        Me.Load()
        Me.BindColors()
    End Sub

    ''' <summary>
    ''' Dispose
    ''' </summary>
    ''' 

    Public Sub Dispose() Implements IDisposable.Dispose
        Me.Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Private Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If _Pen_DegradeClair0 IsNot Nothing Then
                _Pen_DegradeClair0.Dispose()
            End If
            _Pen_DegradeClair0 = Nothing
            If _Pen_DegradeClair1 IsNot Nothing Then
                _Pen_DegradeClair1.Dispose()
            End If
            _Pen_DegradeClair1 = Nothing
            If _Pen_DegradeFonce0 IsNot Nothing Then
                _Pen_DegradeFonce0.Dispose()
            End If
            _Pen_DegradeFonce0 = Nothing
            If _Pen_DegradeFonce1 IsNot Nothing Then
                _Pen_DegradeFonce1.Dispose()
            End If
            _Pen_DegradeFonce1 = Nothing
            If _Pen_Borders IsNot Nothing Then
                _Pen_Borders.Dispose()
            End If
            _Pen_Borders = Nothing

            If _Brush_DegradeClair0 IsNot Nothing Then
                _Brush_DegradeClair0.Dispose()
            End If
            _Brush_DegradeClair0 = Nothing
            If _Brush_DegradeClair1 IsNot Nothing Then
                _Brush_DegradeClair1.Dispose()
            End If
            _Brush_DegradeClair1 = Nothing
            If _Brush_DegradeFonce0 IsNot Nothing Then
                _Brush_DegradeFonce0.Dispose()
            End If
            _Brush_DegradeFonce0 = Nothing
            If _Brush_DegradeFonce1 IsNot Nothing Then
                _Brush_DegradeFonce1.Dispose()
            End If
            _Brush_DegradeFonce1 = Nothing
            If _Brush_Text IsNot Nothing Then
                _Brush_Text.Dispose()
            End If
            _Brush_Text = Nothing
            If _Brush_Text_Focus IsNot Nothing Then
                _Brush_Text_Focus.Dispose()
            End If
            _Brush_Text_Focus = Nothing
            If _Brush_Text_Desabled IsNot Nothing Then
                _Brush_Text_Desabled.Dispose()
            End If
            _Brush_Text_Desabled = Nothing
            If _Brush_Titre IsNot Nothing Then
                _Brush_Titre.Dispose()
            End If
            _Brush_Titre = Nothing
        End If
    End Sub

    Protected Overrides Sub Finalize()
        Try
            Me.Dispose(False)
        Finally
            MyBase.Finalize()
        End Try
    End Sub

#End Region

#Region "Propriétés"

    Public ReadOnly Property ColorDegradeClair0() As Color
        Get
            Return _Color_DegradeClair0
        End Get
    End Property
    Public ReadOnly Property PenDegradeClair0() As Pen
        Get
            Return _Pen_DegradeClair0
        End Get
    End Property
    Public ReadOnly Property BrushDegradeClair0() As Brush
        Get
            Return _Brush_DegradeClair0
        End Get
    End Property

    Public ReadOnly Property ColorDegradeClair1() As Color
        Get
            Return _Color_DegradeClair1
        End Get
    End Property
    Public ReadOnly Property PenDegradeClair1() As Pen
        Get
            Return _Pen_DegradeClair1
        End Get
    End Property
    Public ReadOnly Property BrushDegradeClair1() As Brush
        Get
            Return _Brush_DegradeClair1
        End Get
    End Property

    Public ReadOnly Property ColorDegradeFonce0() As Color
        Get
            Return _Color_DegradeFonce0
        End Get
    End Property
    Public ReadOnly Property PenDegradeFonce0() As Pen
        Get
            Return _Pen_DegradeFonce0
        End Get
    End Property
    Public ReadOnly Property BrushDegradeFonce0() As Brush
        Get
            Return _Brush_DegradeFonce0
        End Get
    End Property

    Public ReadOnly Property ColorDegradeFonce1() As Color
        Get
            Return _Color_DegradeFonce1
        End Get
    End Property
    Public ReadOnly Property PenDegradeFonce1() As Pen
        Get
            Return _Pen_DegradeFonce1
        End Get
    End Property
    Public ReadOnly Property BrushDegradeFonce1() As Brush
        Get
            Return _Brush_DegradeFonce1
        End Get
    End Property

    Public ReadOnly Property ColorDegradeFocusClair0() As Color
        Get
            Return _Color_DegradeFocusClair0
        End Get
    End Property
    Public ReadOnly Property ColorDegradeFocusClair1() As Color
        Get
            Return _Color_DegradeFocusClair1
        End Get
    End Property

    Public ReadOnly Property ColorDegradeFocusFonce0() As Color
        Get
            Return _Color_DegradeFocusFonce0
        End Get
    End Property
    Public ReadOnly Property ColorDegradeFocusFonce1() As Color
        Get
            Return _Color_DegradeFocusFonce1
        End Get
    End Property

    Public ReadOnly Property ColorBack() As Color
        Get
            Return _Color_Back
        End Get
    End Property
    Public ReadOnly Property ColorBackForm() As Color
        Get
            Return _Color_BackForm
        End Get
    End Property

    Public ReadOnly Property ColorText() As Color
        Get
            Return _Color_Text
        End Get
    End Property
    Public ReadOnly Property BrushText() As Brush
        Get
            Return _Brush_Text
        End Get
    End Property

    Public ReadOnly Property ColorTextFocus() As Color
        Get
            Return _Color_Text_Focus
        End Get
    End Property
    Public ReadOnly Property BrushTextFocus() As Brush
        Get
            Return _Brush_Text_Focus
        End Get
    End Property

    Public ReadOnly Property ColorTextDesabled() As Color
        Get
            Return _Color_Text_Desabled
        End Get
    End Property
    Public ReadOnly Property BrushTextDesabled() As Brush
        Get
            Return _Brush_Text_Desabled
        End Get
    End Property

    Public ReadOnly Property ColorTitre() As Color
        Get
            Return _Color_Titre
        End Get
    End Property
    Public ReadOnly Property BrushTitre() As Brush
        Get
            Return _Brush_Titre
        End Get
    End Property

    Public ReadOnly Property ColorBorders() As Color
        Get
            Return _Color_Borders
        End Get
    End Property
    Public ReadOnly Property PenBorders() As Pen
        Get
            Return _Pen_Borders
        End Get
    End Property

#End Region

#Region "Methodes Publics"

    Public Shared Sub Montrer()
        'Création d'un formulaire
        ''Dim f As New FormStylesCouleurs()
        'Affichage
        ''f.Montrer()
        'Libération mémoire
        ''f = Nothing
    End Sub

    Private Sub Load()
        ''''Me._Color_Titre = My.MySettings.Default.Color_Titre
        ''''Me._Color_Borders = My.MySettings.Default.Color_Borders
    End Sub

    ''' <summary>
    ''' Sauvegarde des parametres
    ''' </summary>
    ''' <returns></returns>
    Public Function Save() As [Boolean]
        Try

            ''''My.MySettings.Default.Color_Titre = Me._Color_Titre
            ''''My.MySettings.Default.Color_Borders = Me._Color_Borders

            My.MySettings.Default.Save()
            Return True
        Catch ex As Exception
            'Erreurs.Enregistrer("Enregistrment de la palette de couleurs impossible.", True, ex)
            Return False
        End Try
    End Function

#End Region

#Region "Methodes Private"

    ''' <summary>
    ''' Chargement des pen et brushes en fonction des couleurs choisies
    ''' </summary>
    Friend Sub BindColors()
        _Pen_DegradeClair0 = New Pen(_Color_DegradeClair0)
        _Brush_DegradeClair0 = New SolidBrush(_Color_DegradeClair0)

        _Pen_DegradeClair1 = New Pen(_Color_DegradeClair1)
        _Brush_DegradeClair1 = New SolidBrush(_Color_DegradeClair1)

        _Pen_DegradeFonce0 = New Pen(_Color_DegradeFonce0)
        _Brush_DegradeFonce0 = New SolidBrush(_Color_DegradeFonce0)

        _Pen_DegradeFonce1 = New Pen(_Color_DegradeFonce1)
        _Brush_DegradeFonce1 = New SolidBrush(_Color_DegradeFonce1)

        _Brush_Text = New SolidBrush(_Color_Text)

        _Brush_Text_Focus = New SolidBrush(_Color_Text_Focus)
        _Brush_Text_Desabled = New SolidBrush(_Color_Text_Desabled)

        _Brush_Titre = New SolidBrush(_Color_Titre)

        _Pen_Borders = New Pen(_Color_Borders)
    End Sub

    Public Sub Reset()
        ' reset des ressources
        My.MySettings.Default.Reset()

        Me.Load()

        'Demander un refresh pour lancer un nouveau singleton
        Me.Refresh()
    End Sub

    ''' <summary>
    ''' Refresh de toutes les interfaces
    ''' </summary>
    Public Sub Refresh()
        Me.BindColors()

        For Each form As Form In Application.OpenForms
            form.Refresh()
        Next
    End Sub

#End Region

End Class
